<?php
session_start();
$user = isset($_SESSION["user"])?$_SESSION["user"]:null;
$theme =isset($_GET["theme"])?$_GET["theme"]:"";
if(!$theme){
    $theme = isset($_COOKIE["theme"])?$_COOKIE["theme"]:"";
}else{
    setcookie("theme",$theme);
}
if(!$theme){
    $theme = "default";
}

function createDb(){
    return new mysqli("localhost","root","","myblog");
}

function makePageUrl($pageIndex){
    $querystring = "pageIndex=$pageIndex";
    foreach($_GET as $k=>$v){
        if($k==="pageIndex"){
            continue;
        }
        $querystring.="&$k=$v";
    }
    return $querystring;
}

function getParam($name){
    $value = isset($_GET[$name])?trim($_GET[$name]):"";
    $value = str_replace("'","''",$value);
    return $value;
}
?>